<?PHP
$reqlevel = 1;
include "membersonly.inc.php";
//include "../config.php";

$status = $_GET["status"];
$sid = $_GET["sid"];
$do = $_GET["do"];
$title = $_POST["title"];
$description = $_POST["description"];
$progress = $_POST["progress"];
$category = $_POST["category"];
$fin_dateX = $_POST["fin_dateX"];
$sort = $_GET["sort"];
$order = $_GET["order"];
$p = $_GET["p"];




function formatDescription($Message){
$Message =str_replace ("&","&amp;",$Message);
$Message =str_replace ("<","&lt;",$Message);
$Message =str_replace (">","&gt;",$Message);
$Message =str_replace ("&lt;b&gt;","<b>",$Message);
$Message =str_replace ("&lt;/b&gt;","</b>",$Message);
$Message =str_replace ("&lt;i&gt;","<i>",$Message);
$Message =str_replace ("&lt;/i&gt;","</i>",$Message);
$Message =str_replace ("&lt;u&gt;","<u>",$Message);
$Message =str_replace ("&lt;/u&gt;","</u>",$Message);
$Message =str_replace ("&lt;strong&gt;","<strong>",$Message);
$Message =str_replace ("&lt;/strong&gt;","</strong>",$Message);
$Message =str_replace ("&lt;em&gt;","<em>",$Message);
$Message =str_replace ("&lt;/em&gt;","</em>",$Message);
$Message =str_replace ("&lt;br&gt;","<br>",$Message);
$Message =str_replace ("&lt;p&gt;","<p>",$Message);
$Message =str_replace ("&lt;/p&gt;","</p>",$Message);
$Message =str_replace ("&lt;br /&gt;","<br />",$Message);
$Message = nl2br($Message);
return $Message;
}



$ver = "1.5a";
$categoryG = array(
		1=>"CALL",
		2=>"CUSTOMER",
		3=>"LAYOUT",
		4=>"MEETING",
		5=>"SCRIPT",
		6=>"SERVICE",
		7=>"TODO",
		8=>"WWW"
	      );



echo "
<style fprolloverstyle>
A {
text-decoration: none;
color: #000000;
}
A:hover {
text-decoration: underline;
font-weight: bold;
}
</style>
<center>
<table border='0' width='911' height='6' cellspacing='0' cellpadding='0' style='font-family: Verdana; font-size: 8pt; font-weight: bold'>
	<tr>
		<td height='20' width='903' align='center' style='background-color: #0058B0; color:#FFFFFF' colspan='9' valign='top'><a href='$php_self?act=0'><span style='text-decoration: none'><font color='#FFFFFF'>HOME</span></font></a> :: <a href='$php_self?act=new'><span style='text-decoration: none'><font color='#FFFFFF'>ADD NEW +</span></font></a> :: <a href='$php_self?status=1'><span style='text-decoration: none'><font color='#FFFFFF'>DONE TASKS</span></font></a> :: <a href='$php_self?act=search'><span style='text-decoration: none'><font color='#FFFFFF'>SEARCH</span></font></a> <a href='in.php'>GO BACK</a></td>
	</tr>
";


if (!$act) {

if ($status != 1) { $status = 0; }
if (empty($do)) { $link1 = "$link1 WHERE status = '$status'"; }

/********************* SEARCH ENGINE *********************/

if ($do == "search") {

$search_for = $_POST["search_for"];
$search_in = $_POST["search_in"];
$search_by = $_POST["search_by"];

$search_for = str_replace("*", "%", $search_for);

$error = "";
if ($search_for == "") { $error = "$error <li> Please type a phrase you'r looking for.</li>"; }
if ($search_in == 0) { $error = "$error <li> Please choose place where you wanna search in.</li>"; }
if ($search_by == "") { $error = "$error <li> Please select by what criteria you would like to search.</li>"; }

if ($error == "") {

// SEARCH IN BOTH //
//****************//

if ($search_in == 1) {  // <----------------------------------    SEARCH IN BOTH 1

if ($search_by == "id") {
$link1 = "$link1 WHERE `sid` = '$search_for'";
} // END BY ID

if ($search_by == "title") {
$link1 = "$link1 WHERE `title` LIKE '$search_for'";
} // END BY TITLE

if ($search_by == "progress") {
$link1 = "$link1 WHERE `progress` = '$search_for'";
} // END BY TITLE


} else if ($search_in == 2) { // <----------------------------------    SEARCH IN DONE TASKS 2


if ($search_by == "id") {
$link1 = "$link1 WHERE `sid` = '$search_for' AND `status` = '1'";
} // END BY ID

if ($search_by == "title") {
$link1 = "$link1 WHERE `title` LIKE '$search_for' AND `status` = '1'";
} // END BY TITLE

if ($search_by == "progress") {
$link1 = "$link1 WHERE `progress` = '$search_for' AND `status` = '1'";
} // END BY TITLE

} else if ($search_in == 3) {  // <----------------------------------    SEARCH IN PENDING TASKS 3

if ($search_by == "id") {
$link1 = "$link1 WHERE `sid` = '$search_for' AND `status` = '0'";
} // END BY ID

if ($search_by == "title") {
$link1 = "$link1 WHERE `title` LIKE '$search_for' AND `status` = '0'";
} // END BY TITLE

if ($search_by == "progress") {
$link1 = "$link1 WHERE `progress` = '$search_for' AND `status` = '0'";
} // END BY TITLE

} // END SEARCH_IN


$link2 = "&do=search&search_in=$search_in&search_by=$search_by&search_for=$search_for";

} // END ERROR CHECK

} // END DO=SEARCH


/********************* END SEARCH ENGINE *********************/

/////////////////// SORTING MACHINE ;-P ///////////////////////////
if (!empty($status)) { $stat = "&status=1"; }
if ($sort == "sid") {
if ($order == "ASC") {
$linkI = "<a href='$php_self?sort=sid&order=DESC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>ID&raquo;</b></span></a>";
} else if ($order == "DESC") {
$linkI = "<a href='$php_self?sort=sid&order=ASC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>ID&laquo;</b></span></a>";
}
} else { $linkI = "<a href='$php_self?sort=sid&order=ASC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>ID&nbsp;&nbsp;</b></span></a>"; }

if ($sort == "title") {
if ($order == "ASC") {
$linkT = "<a href='$php_self?sort=title&order=DESC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>TITLE&raquo;</b></span></a>";
} else if ($order == "DESC") {
$linkT = "<a href='$php_self?sort=title&order=ASC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>TITLE&laquo;</b></span></a>";
}
} else { $linkT = "<a href='$php_self?sort=title&order=ASC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>TITLE&nbsp;&nbsp;</b></span></a>"; }

if ($sort == "progress") {
if ($order == "ASC") {
$linkP = "<a href='$php_self?sort=progress&order=DESC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>PROGRESS&raquo;</b></span></a>";
} else if ($order == "DESC") {
$linkP = "<a href='$php_self?sort=progress&order=ASC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>PROGRESS&laquo;</b></span></a>";
}
} else { $linkP = "<a href='$php_self?sort=progress&order=ASC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>PROGRESS&nbsp;&nbsp;</b></span></a>"; }

if ($sort == "add_date") {
if ($order == "ASC") {
$linkD = "<a href='$php_self?sort=add_date&order=DESC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>ADD DATE&raquo;</b></span></a>";
} else if ($order == "DESC") {
$linkD = "<a href='$php_self?sort=add_date&order=ASC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>ADD DATE&laquo;</b></span></a>";
}
} else { $linkD = "<a href='$php_self?sort=add_date&order=ASC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>ADD DATE&nbsp;&nbsp;</b></span></a>"; }

if ($sort == "category") {
if ($order == "ASC") {
$linkC = "<a href='$php_self?sort=category&order=DESC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>CATEGORY&raquo;</b></span></a>";
} else if ($order == "DESC") {
$linkC = "<a href='$php_self?sort=category&order=ASC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>CATEGORY&laquo;</b></span></a>";
}
} else { $linkC = "<a href='$php_self?sort=category&order=ASC$stat$link2'><span style='text-decoration: none'><font color='FFFFFF'><b>CATEGORY&nbsp;&nbsp;</b></span></a>"; }

if (!empty($sort)) { $link1 = "$link1 ORDER BY `$sort` $order"; }

$sql = mysql_query("SELECT * FROM `".$DBprefix."todo` $link1");
$count = mysql_num_rows($sql);


/////////////////// SORTING MACHINE END ///////////////////////////



echo "
	<tr>
		<td height='13' width='38' align='center' style='background-color: #0058B0; color:#FFFFFF'>$linkI</td>
		<td height='13' width='108' align='center' style='background-color: #0058B0; color:#FFFFFF'>ADD BY</td>
		<td height='13' width='108' align='center' style='background-color: #0058B0; color:#FFFFFF'>$linkC</td>
		<td height='13' width='68' align='center' style='background-color: #0058B0; color:#FFFFFF'>$linkT</td>
		<td height='13' width='229' align='center' style='background-color: #0058B0; color:#FFFFFF'>DESCRIPTION</td>
		<td height='13' width='84' align='center' style='background-color: #0058B0; color:#FFFFFF'>$linkP</td>
		<td height='13' width='94' align='center' style='background-color: #0058B0; color:#FFFFFF'>$linkD</td>
		<td height='13' width='95' align='center' style='background-color: #0058B0; color:#FFFFFF'>FINISH DATE</td>
		<td height='13' width='195' align='center' style='background-color: #0058B0; color:#FFFFFF'>OPTIONS</td>
	</tr>
	<tr>
		<td align='center' style='background-color: #B3D9FF' colspan='9' valign='top'>";
$search_for = str_replace("%", "*", $search_for);
if ($error != "") { echo "<br>! YOUR SEARCH CANNOT BE COMPLETED !<br><br><font color='red'><ul>$error</ul></font><a href='javascript:history.go(-1)'><- GO BACK!</a><br>&nbsp;"; } else if ($do == "search") { echo "<br>You are searching for: <font color='#000099'>$search_for</font><br>Results found: <font color='#000099'>$count</font>"; if ($count == 0) { echo "<br><br><a href='javascript:history.go(-1)'><- GO BACK!</a><br>&nbsp;"; } else { echo "<br>&nbsp;"; } $show = "yes"; } else { echo "<br>Tasks: <font color='#000099'>$count</font><br>&nbsp;";  $show = "yes";}

echo "</td>
	</tr>";


if ($show == "yes") {
while ($row=mysql_fetch_array($sql))
{
$sid = $row["sid"];
$uid = $row["uid"];
$title = $row["title"];
$category = $row["category"];
$categoryS = @$categoryG[$category];
$description = $row["description"];
$progress = $row["progress"];
$add_date = $row["add_date"];
$fin_date = $row["fin_date"];
$add_dateS = date("m-d-y", $add_date);
$fin_dateS = date("m-d-y", $fin_date);
$statusX = $row["status"];

$uidn1 = mysql_query("SELECT `user_name` FROM `".$DBprefix."signup` WHERE `user_id` = '$uid'");
while ($uidn2 = mysql_fetch_array($uidn1)){
$uidn = strtoupper($uidn2["user_name"]);
}

///////////// MAKE SHORT DESCRIPTIONS ////////////////

$countD = strlen($description);
if ($countD >= "25") {
$description = substr($description, 0, 25);
$description = "<a href='$php_self?act=more&sid=$sid'><font color='000000'><b>$description...</b></a>";
}

///////////// END SHORT DESCRIPTIONS ////////////////


/////////////////// CHANGE BG COLORS WHEN EXPIRATION DATES ARE CLOSER ////////////

$days1 = $fin_date - 86400;
$days2 = $fin_date - 172800;
$days4 = $fin_date - 345600;

if ($timedate >= $fin_date) { $bgcolor = "#800000"; }
else if ($timedate >= $days1) { $bgcolor = "#FF4040"; } 
else if ($timedate >= $days2) { $bgcolor = "#FF9966"; } 
else if ($timedate >= $days4) { $bgcolor = "#FFFF66"; } 
else { $bgcolor = "#B3D9FF"; }

// #FFFF66 - YELLOW
// #FF9966 - ORANGE
// #FF4040 - RED

//////////////////////////////// END BG COLOR CHANGE //////////////////////////////

if ($progress == "100") {
$query = "UPDATE `".$DBprefix."todo` SET status = '1' WHERE progress = '100'";
$result = mysql_query($query);
} else if ($statusX == 1) {
$query = "UPDATE `".$DBprefix."todo` SET progress = '100' WHERE status = '1'";
$result = mysql_query($query);
}

echo "
	<tr onMouseOver=\"this.bgColor='#CCFF99';\" onMouseOut=\"this.bgColor='$bgcolor';\" bgcolor='$bgcolor'>
    	<span style='font-weight: 400' text-decoration: line-through'>
		<td align='center'>$sid</td>
		<td align='center'>$uidn</td>
		<td align='center'>$categoryS</td>
		<td align='center'>$title</td>
		<td align='center'>$description</td>
		<td align='center'>$progress%</td>
		<td align='center'>$add_dateS</td>
		<td align='center'>$fin_dateS</td>
";
if ($statusX == 1) { echo "<td align='center'><font color='green'><b>COMPLETED</b></font> &nbsp; <a href='$php_self?act=del&sid=$sid'><span style='text-decoration: none'><font color='red'><b>DELETE</b></span></font></a></td>"; } else {
                    echo "<td align='center'><a href='$php_self?act=progress&do=down&p=$progress&sid=$sid'><span style='text-decoration: none'><font color='red'><b>-</b></span></font></a> &nbsp; <a href='$php_self?act=progress&do=up&p=$progress&sid=$sid'><span style='text-decoration: none'><font color='green'><b>+</b></span></font></a> | <a href='$php_self?act=del&sid=$sid'><span style='text-decoration: none'><font color='red'><b>DELETE</b></span></font></a> &nbsp; <a href='$php_self?act=mdone&sid=$sid'><span style='text-decoration: none'><font color='green'><b>DONE</b></span></font></a></td>"; }
echo "
		</span>
	</tr>
";
} // END WHILE
} // END SHOW YES


} // END ACT DISPLAY

if ($act == "new") {
if ($do != "save") {
echo "
<form  method='POST' action='$php_self?act=new&do=save'>
	<tr>
		<td align='center' style='background-color: #B3D9FF' colspan='9' valign='top'>&nbsp;</td>
	</tr>

	<tr>
		<td height='13' width='108' align='right' style='background-color: #B3D9FF'>TITLE: </td>
		<td height='13' width='620' align='left' style='background-color: #B3D9FF'>&nbsp;<input type='text' name='title' style='color: #000099; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #D7D7D7' size='23'></td>
	</tr>
	<tr>
		<td height='13' width='108' align='right' style='background-color: #B3D9FF'>DESCRIPTION: </td>
		<td height='13' width='620' align='left' style='background-color: #B3D9FF'>&nbsp;<textarea rows='5' name='description' cols='23' style='color: #000099; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #D7D7D7'></textarea></td>
		</tr>
	<tr>
		<td height='6' width='108' align='right' style='background-color: #B3D9FF'>
		PROGRESS: </td>
		<td height='6' width='620' align='left' style='background-color: #B3D9FF'>&nbsp;<input type='text' name='progress' style='color: #000099; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #D7D7D7' size='23'></td>
		</tr>
	<tr>
		<td height='9' width='108' align='right' style='background-color: #B3D9FF'>CATEGORY:</td>
		<td height='9' width='620' align='left' style='background-color: #B3D9FF'>
		&nbsp;<select name='category' size='1' style='color: #000099; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #D7D7D7'>
<option selected value='0'>------ CHOOSE ------</option>
<option value='1'>CALL</option>
<option value='2'>CUSTOMER</option>
<option value='3'>LAYOUT</option>
<option value='4'>MEETING</option>
<option value='5'>SCRIPT</option>
<option value='6'>SERVICE</option>
<option value='7'>TODO</option>
<option value='8'>WWW</option>
</select>
		</td>
		</tr>
	<tr>
		<td height='18' width='108' align='right' style='background-color: #B3D9FF'>FINISH DATE:</td>
		<td height='18' width='620' align='left' style='background-color: #B3D9FF'>
		&nbsp;<select name='fin_dateX' size='1' style='color: #000099; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #D7D7D7'>
<option selected value='0'>------ CHOOSE ------</option>
<option value='86400'>1 DAY</option>
<option value='432000'>5 DAYS</option>
<option value='864000'>10 DAYS</option>
<option value='2592000'>30 DAYS</option>
</select>
		</td>
	</tr>
	<tr>
		<td height='8' width='108' align='right' style='background-color: #B3D9FF'></td>
		<td height='8' width='620' align='left' style='background-color: #B3D9FF'></td>
		</tr>
	<tr>
		<td height='5' width='108' align='right' style='background-color: #B3D9FF'></td>
		<td height='5' width='620' align='left' style='background-color: #B3D9FF'><input type='submit' value='ADD NEW TASK' style='color: #FFFFFF; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #0058B0'></td>
		</tr>
</form>
";
} else {

$error = "";

if ($title == "") { $error = "$error <li> Please type a title for the new TASK.</li>"; }
if ($description == "") { $error = "$error <li> Please type a description for the new TASK.</li>"; }
if ($category == 0) { $error = "$error <li> Please select a category.</li>"; }
if ($fin_dateX == 0) { $error = "$error <li> Please select deadline.</li>"; }

if ($error != "") {

echo "
	<tr>
		<td height='49' width='728' align='center' style='background-color: #B3D9FF'><br>! NEW TASK CANT BE ADDED !<br><br><font color='red'><ul>$error</ul></font><a href='javascript:history.go(-1)'><- GO BACK!</a><br>&nbsp;</td>
	</tr>
";
} else {


$Fdate = $timedate + $fin_dateX;
if (empty($progress)) { $progress = 0; }
$query = "INSERT INTO `".$DBprefix."todo` (`uid`,`category`, `title`, `description`, `progress`, `add_date`, `fin_date`) VALUES ('$info_user_id','$category','$title','$description','$progress','$timedate','$Fdate')";  
$result = mysql_query($query); 
echo "
	<tr>
		<td height='49' width='728' align='right' style='background-color: #B3D9FF'><p align='center'>! SUCCESS A NEW TASK HAS BEEN ADDED !<br><br>BETTER DO IT !!!</td>
	</tr>
";
} // END ERROR CHECK

} // END DO SAVE

} // END ADD NEW


if ($act == "progress") {

if ($do == "up") {
$p = $p + 10;
$query = "UPDATE `".$DBprefix."todo` SET progress = '$p' WHERE sid = '$sid'";
$result = mysql_query($query);
echo "
	<tr>
		<td height='49' width='728' align='right' style='background-color: #B3D9FF'><p align='center'>! SUCCESS PROGRESS INCREASED BY 10% !<br><br>GOOD :-) !!!</td>
	</tr>
";
} // END DO PROGRESS UP
if ($do == "down") {
$p = $p - 10;
$query = "UPDATE `".$DBprefix."todo` SET progress = '$p' WHERE sid = '$sid'";
$result = mysql_query($query);
echo "
	<tr>
		<td height='49' width='728' align='right' style='background-color: #B3D9FF'><p align='center'>! SUCCESS PROGRESS DECREASED BY 10% !<br><br>NOT GOOD :-/ !!!</td>
	</tr>
";
} // END DO PROGRESS DOWN

} // END PROGRESS BAR


if ($act == "del") {
$query = "DELETE from `".$DBprefix."todo` WHERE sid='$sid'";
$result = mysql_query($query);

echo "
	<tr>
		<td height='49' width='728' align='right' style='background-color: #B3D9FF'><p align='center'>! SUCCESS TASK HAS BEEN DELETED !<br><br>NOT GOOD :-/ !!!</td>
	</tr>
";
} // END ACT DELETE


if ($act == "mdone") {
$query = "UPDATE `".$DBprefix."todo` SET status = '1' WHERE sid = '$sid'";
$result = mysql_query($query);

echo "
	<tr>
		<td height='49' width='728' align='right' style='background-color: #B3D9FF'><p align='center'>! SUCCESS TASK HAS BEEN COMPLETED !<br><br>VERY GOOD BOSS !!!</td>
	</tr>
";
} // END ACT MARK AS DONE


if ($act == "more") {

$sql = mysql_query("SELECT * FROM `".$DBprefix."todo` WHERE `sid` = '$sid'");
$count = mysql_num_rows($sql);

while ($row=mysql_fetch_array($sql))
{
$sid = $row["sid"];
$title = $row["title"];
$description = $row["description"];
$descriptionS = formatDescription($row["description"]);
$progress = $row["progress"];
$category = $row["category"];
$categoryS = @$categoryG[$category];
$add_date = $row["add_date"];
$fin_date = $row["fin_date"];
$add_dateS = date("m-d-y", $add_date);
$fin_dateS = date("m-d-y", $fin_date);
}

if (!$do) {
echo "
	<tr>
		<td align='center' style='background-color: #B3D9FF' colspan='9' valign='top'>&nbsp</td>
	</tr>

	<tr>
		<td height='13' width='223' style='background-color: #B3D9FF' align='right'>ID:</td>
		<td height='13' width='4' align='left' style='background-color: #B3D9FF'></td>
		<td height='13' width='338' align='left' style='background-color: #B3D9FF; color:#000099';>$sid</td>
		<td height='13' width='275' align='right' style='background-color: #B3D9FF'></td>
	</tr>
	<tr>
		<td height='13' width='223' style='background-color: #B3D9FF' align='right'>ADD BY:</td>
		<td height='13' width='4' align='left' style='background-color: #B3D9FF'></td>
		<td height='13' width='338' align='left' style='background-color: #B3D9FF; color:#000099';>$sid</td>
		<td height='13' width='275' align='right' style='background-color: #B3D9FF'></td>
	</tr>
	<tr>
		<td height='13' width='223' style='background-color: #B3D9FF' align='right'>CATEGORY:</td>
		<td height='13' width='4' align='left' style='background-color: #B3D9FF'></td>
		<td height='13' width='338' align='left' style='background-color: #B3D9FF; color:#015EC5';>$categoryS</td>
		<td height='13' width='275' align='right' style='background-color: #B3D9FF'></td>
	</tr>
	<tr>
		<td height='13' width='223' style='background-color: #B3D9FF' align='right'>TITLE:</td>
		<td height='13' width='4' align='left' style='background-color: #B3D9FF'></td>
		<td height='13' width='338' align='left' style='background-color: #B3D9FF; color:#000099';>$title</td>
		<td height='13' width='275' align='right' style='background-color: #B3D9FF'></td>
	</tr>
	<tr>
		<td height='13' width='223' style='background-color: #B3D9FF' align='right'>PROGRESS:</td>
		<td height='13' width='4' align='left' style='background-color: #B3D9FF'></td>
		<td height='13' width='338' align='left' style='background-color: #B3D9FF; color:#000099'>$progress%</td>
		<td height='13' width='275' align='right' style='background-color: #B3D9FF'></td>
	</tr>
	<tr>
		<td height='13' width='223' style='background-color: #B3D9FF' align='right'>ADD DATE:</td>
		<td height='13' width='4' align='left' style='background-color: #B3D9FF'></td>
		<td height='13' width='338' align='left' style='background-color: #B3D9FF; color:#000099';>$add_dateS</td>
		<td height='13' width='275' align='right' style='background-color: #B3D9FF'></td>
	</tr>
	<tr>
		<td height='47' width='223' style='background-color: #B3D9FF' align='right' valign='top'>DESCRIPTION:</td>
		<td height='47' width='4' align='left' style='background-color: #B3D9FF' valign='top'>&nbsp;</td>
		<td height='47' width='338' align='left' style='background-color: #B3D9FF; color:#000099' valign='top'>$descriptionS</td>
		<td height='47' width='275' align='right' style='background-color: #B3D9FF'>&nbsp;</td>
	</tr>
	<tr>
		<td height='19' width='223' style='background-color: #B3D9FF' align='right' valign='top'>&nbsp;</td>
		<td height='19' width='4' align='left' style='background-color: #B3D9FF' valign='top'>&nbsp;</td>
		<td height='19' width='338' align='left' style='background-color: #B3D9FF' valign='top'><a href='$php_self?act=progress&do=up&p=$progress&sid=$sid'><img src='../g/ico_thumb_up.gif' border='0'></a> &nbsp; <a href='$php_self?act=progress&do=down&p=$progress&sid=$sid'><img src='../g/ico_thumb_down.gif' border='0'></a> | <a href='$php_self?act=more&do=edit&sid=$sid'><img src='../g/ico_edit.gif' border='0'></a> &nbsp; <a href='$php_self?act=del&sid=$sid'><img src='../g/ico_delete.gif' border='0'></a> &nbsp; <a href='$php_self?act=mdone&sid=$sid'><span style='text-decoration: none'><font color='green'><b>MARK AS DONE</b></span></font></a> </td>
		<td height='19' width='275' align='right' style='background-color: #B3D9FF'>&nbsp;</td>
	</tr>
";

}  // END DO=SHOW

if ($do == "edit") {

if ($category == 1) { $s1 = "SELECTED"; }
if ($category == 2) { $s2 = "SELECTED"; }
if ($category == 3) { $s3 = "SELECTED"; }
if ($category == 4) { $s4 = "SELECTED"; }
if ($category == 5) { $s5 = "SELECTED"; }
if ($category == 6) { $s6 = "SELECTED"; }
if ($category == 7) { $s7 = "SELECTED"; }
if ($category == 8) { $s8 = "SELECTED"; }

  

  $difference = $fin_date - $timedate;


  $days_left = floor($difference/60/60/24);
  $hours_left = floor(($difference - $days_left*60*60*24)/60/60);
  $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
  $seconds_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60 - $minutes_left*60));

// $description = str_replace("<br />","", $description); // REPLACE <BR> TAGS NOT NEED NEMORE

echo "
<form  method='POST' action='$php_self?act=more&do=save&sid=$sid'>
	<tr>
		<td align='center' style='background-color: #B3D9FF' colspan='9' valign='top'>&nbsp;</td>
	</tr>

	<tr>
		<td height='13' width='108' align='right' style='background-color: #B3D9FF'>ID: </td>
		<td height='13' width='620' align='left' style='background-color: #B3D9FF'>&nbsp;$sid</td>
	</tr>
	<tr>
		<td height='13' width='108' align='right' style='background-color: #B3D9FF'>TITLE: </td>
		<td height='13' width='620' align='left' style='background-color: #B3D9FF'>&nbsp;<input type='text' name='title1' value='$title' style='color: #000099; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #D7D7D7' size='23'></td>
	</tr>
	<tr>
		<td height='13' width='108' align='right' style='background-color: #B3D9FF'>DESCRIPTION: </td>
		<td height='13' width='620' align='left' style='background-color: #B3D9FF'>&nbsp;<textarea rows='7' name='description1' cols='30' style='color: #000099; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #D7D7D7'>$description</textarea></td>
		</tr>
	<tr>
		<td height='6' width='108' align='right' style='background-color: #B3D9FF'>
		PROGRESS: </td>
		<td height='6' width='620' align='left' style='background-color: #B3D9FF'>&nbsp;<input type='text' value='$progress' name='progress1' style='color: #000099; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #D7D7D7' size='23'></td>
		</tr>
	<tr>
		<td height='9' width='108' align='right' style='background-color: #B3D9FF'>CATEGORY:</td>
		<td height='9' width='620' align='left' style='background-color: #B3D9FF'>
		&nbsp;<select name='category1' size='1' style='color: #000099; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #D7D7D7'>
<option selected value='0'>------ CHOOSE ------</option>
<option value='1' $s1>CALL</option>
<option value='2' $s2>CUSTOMER</option>
<option value='3' $s3>LAYOUT</option>
<option value='4' $s4>MEETING</option>
<option value='5' $s5>SCRIPT</option>
<option value='6' $s6>SERVICE</option>
<option value='7' $s7>TODO</option>
<option value='8' $s8>WWW</option>
</select>
		</td>
		</tr>
	<tr>
		<td height='18' width='108' align='right' style='background-color: #B3D9FF'>ADD DATE:</td>
		<td height='18' width='620' align='left' style='background-color: #B3D9FF'>	&nbsp;$add_dateS</td>
	</tr>
	<tr>
		<td height='18' width='108' align='right' style='background-color: #B3D9FF'>TIME LEFT:</td>
		<td height='18' width='620' align='left' style='background-color: #B3D9FF'>	&nbsp;<font color='#000099'>DAYS:</font> $days_left <font color='#000099'>HOURS:</font> $hours_left <font color='#000099'>MINUTES:</font> $minutes_left <font color='#000099'>SECONDS:</font> $seconds_left</td>
	</tr>
	<tr>
		<td height='18' width='108' align='right' style='background-color: #B3D9FF'>ADD TIME:</td>
		<td height='18' width='620' align='left' style='background-color: #B3D9FF'>
		&nbsp;<select name='add_time' size='1' style='color: #000099; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #D7D7D7'>
<option selected value='0'>-- ADD NOTHING --</option>
<option value='86400'>1 DAY</option>
<option value='432000'>5 DAYS</option>
<option value='864000'>10 DAYS</option>
<option value='2592000'>30 DAYS</option>
</select>
		</td>
	</tr>
	<tr>
		<td height='8' width='108' align='right' style='background-color: #B3D9FF'></td>
		<td height='8' width='620' align='left' style='background-color: #B3D9FF'></td>
		</tr>
	<tr>
		<td height='5' width='108' align='right' style='background-color: #B3D9FF'></td>
		<td height='5' width='620' align='left' style='background-color: #B3D9FF'><input type='submit' value='SAVE CHANGES' style='color: #FFFFFF; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #0058B0'></td>
	</tr>
</form>
";

} // END DO EDIT ELSE


if ($do == "save") {
$title1 = $_POST["title1"];
$category1 = $_POST["category1"];
$description1 = $_POST["description1"];
$progress1 = $_POST["progress1"];
$fin_date1 = $_POST["fin_date1"];
$add_time1 = $_POST["add_time"];

if ($add_time1 != 0) { $fin_date1 = $fin_date + $add_time1; } else { $fin_date1 = $fin_date; }


$query = mysql_query("UPDATE `".$DBprefix."todo` SET `title` = '$title1', `category` = '$category1', `description` = '$description1', `progress` = '$progress1', `fin_date` = '$fin_date1' WHERE `sid` = $sid");
echo "
	<tr>
		<td height='49' width='728' align='right' style='background-color: #B3D9FF'><p align='center'>! SUCCESS A NEW TASK HAS BEEN ADDED !<br><br>BETTER DO IT !!!</td>
	</tr>
";

} // END DO=SAVE
} // END ACT MORE


if ($act == "search") {

echo "
<form  method='POST' action='$php_self?do=search'>
	<tr>
		<td align='center' style='background-color: #B3D9FF' colspan='9' valign='top'>&nbsp</td>
	</tr>

	<tr>
		<td height='13' width='164' align='right' style='background-color: #B3D9FF'>SEARCH FOR: </td>
		<td height='13' width='681' align='left' style='background-color: #B3D9FF' colspan='4'>&nbsp;<input type='text' name='search_for' style='color: #000099; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #D7D7D7' size='20'></td>
	</tr>
	<tr>
		<td height='6' width='164' align='right' style='background-color: #B3D9FF'>SEARCH IN: </td>
		<td height='6' width='681' align='left' style='background-color: #B3D9FF' colspan='4'>&nbsp;<select size='1' name='search_in' style='color: #000099; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #D7D7D7'>
		<option value='0'>------ CHOOSE ------</option>
		<option value='1'>BOTH</option>
		<option value='2'>DONE TASKS</option>
		<option value='3'>PENDING TASKS</option>
		</select></td>
	</tr>
	<tr>
		<td height='13' width='164' align='right' style='background-color: #B3D9FF'>SEARCH BY:</td>
		<td height='13' width='51' align='center' style='background-color: #B3D9FF'>&nbsp;<input type='radio' value='id' name='search_by'><br>ID</td>
		<td height='13' width='51' align='center' style='background-color: #B3D9FF'><input type='radio' value='title' name='search_by'><br>TITLE</td>
		<td height='13' width='51' align='center' style='background-color: #B3D9FF'><input type='radio' value='progress' name='search_by'><br>PROGRESS</td>
		<td height='13' width='595' align='left' style='background-color: #B3D9FF'></td>
		</tr>
	<tr>
		<td height='8' width='164' align='right' style='background-color: #B3D9FF'></td>
		<td height='8' width='681' align='left' style='background-color: #B3D9FF' colspan='4'></td>
		</tr>
	<tr>
		<td height='5' width='164' align='right' style='background-color: #B3D9FF'></td>
		<td height='5' width='681' align='left' style='background-color: #B3D9FF' colspan='4'><input type='submit' value='SEARCH' style='color: #FFFFFF; font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #0058B0'></td>
		</tr>
</form>

";

} // END ACT SEARCH 


echo "
	<tr>
		<td align='center' style='background-color: #B3D9FF' colspan='9' valign='top'>&nbsp</td>
	</tr>
	<tr>
		<td align='center' style='background-color: #0058B0; color:#FFFFFF; font-family:Verdana; font-size:7pt; font-weight:bold' colspan='9' valign='top'>TODO SCRIPT VER.: $ver<br>Made by and for DJone so he can remember all his great ideas.<br>&copy ".date(Y) ." IdeaLAN LLC.</td>
	</tr>
</table>
</center>
";

?>